<?php
/**
 * 
 * @author tangbl
 * 
 */
class DishesAction extends CommonAction {
	
	public function _initialize() {
		parent::_initialize();
		parent::_initmenu();	
	}
	
	/**
	 * 列表
	 */
	public function index() {
		if(IS_AJAX){
			
			import('ORG.Util.Page');
			$model     = D("Article");
			
			$orderDesc = $this->_get("orderDirection","trim","desc");;
			$orderName = $this->_get("orderName","trim","addtime");
			$pageNum   = $this->_get("pageNum","intval",C('web_admin_pagenum'));
			$nowPage   = $this->_get("p","intval",1);
			
			$map       = unescape($this->_get("where"));
			$map       = "isdel=2 ".$map;
			$count     = $model->where($map)->count();
			$Page      = new Page($count);
			$list      = $model->where($map)->order($orderName.' '.$orderDesc)
						 ->field("description,content",true)->page($nowPage.','.$pageNum)->select();
			$totalPage = ceil($count/$pageNum);
			C('web_admin_pagenum',$pageNum);
			
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'rows'=>array(),'totalPage'=>$totalPage);
			$upd       = L('cfg_list_itf_btn_modify');
			$del       = L('cfg_list_itf_btn_delete');
			foreach($list AS $row){
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'cateid'   => get_cate_name($row['cateid'],$row['lang']),
						'lang'     => $row['lang'],
						'title'    => $row['title'],
						'addtime'  => date('Y-m-d',$row['addtime']),
						'deal'=>'
						 <a href="#" class="btn green create_url"  data-id="'.$row['id'].'"><i class="icon-link"></i></a>
						 <a href="'.__URL__.'/edit/id/'.$row['id'].'" class="btn blue icn-only" title="'.$upd.'"><i class="icon-edit"></i></a>
						 <a href="#" class="btn red icn-only delAlone" title="'.$del.'" data-id="'.$row['id'].'"><i class="icon-remove"></i></a> '
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
			
		}else{
			$this->display();
		}	
	}
	
	/**
	 * 添加
	 */
	public function add(){
		if(IS_POST){
			$param = array(
				"upload" => array("single"=>array("single")),
				"reply"  => true,
				"cache"  => true,
			);
			parent::do_add("Article",$param);
		} else {
			$lang = $this->_param("lang","",getLang());
			$this->assign("lang",$lang);
			
			$cateid  = $this->_param('cateid','intval',0);
			$this -> assign("cateid",$cateid);

			$this -> assign("jumpUrl",U('Article/add'));
			$this -> display();
		}
	}
	
	/**
	 * 删除
	 */
	public function del(){
		
		$param = array(
			"reply"  => true,
			"cache"  => true,
		);
		parent::do_del("Article",false,$param);
	}
	
	/**
	 * 修改
	 */
	public function edit(){
		
		if(IS_POST) {
			$param = array(
				"upload" => array("single"=>array("single")),
				"reply"  => true,
				"cache"  => true,
			);
			parent::do_edit("Article",$param);
		}else{
			$article   = D("Article");
			$id        = $this->_param('id','intval',0);
			if(!$id) $this->error(L('cfg_form_tipmsg_illgel'));
			
			$data      = $article->find($id); 
			$this->assign("article",$data);
						
			$module    = "Article";
			$single    = find_thumb($data['solevar'],'single',$module);
			$this->assign("single",$single);

			$this->display();
		}
	}
	
}
?>